package cn.stazxr.pool;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.junit.Test;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @author talentestors
 * @version 1.0
 * @since 2025.05.20
 **/
public class PoolTest {

	@Test
	public void test1() throws Exception {
		Properties properties = new Properties();
		properties.load(PoolTest.class.getClassLoader().getResourceAsStream("jdbc.properties"));
		DruidDataSource dataSource = new DruidDataSource();
		dataSource.configFromPropeties(properties);

		Connection connection = dataSource.getConnection();
		System.out.println(connection);
		System.out.println(dataSource.getCreateCount());
		connection.close();
	}

	@Test
	public void test2() throws Exception {
		Properties properties = new Properties();
		properties.load(PoolTest.class.getClassLoader().getResourceAsStream("jdbc.properties"));

		DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
		Connection connection = dataSource.getConnection();
		System.out.println(connection);
		System.out.println(connection.getMetaData().getURL());
		connection.close();
	}

	@Test
	public void test3() throws Exception {
		Properties properties = new Properties();
		properties.load(PoolTest.class.getClassLoader().getResourceAsStream("datasource.properties"));

		HikariConfig hikariConfig = new HikariConfig(properties);
		HikariDataSource dataSource = new HikariDataSource(hikariConfig);
		Connection connection = dataSource.getConnection();
		System.out.println(connection);
		connection.close();
	}

	@Test
	public void test4() throws SQLException {
		System.out.println(DataSourceUtil.DATASOURCE.getConnection());
	}

}
